package com.ac.app.web.action.pick;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.caac.core.config.QueryClass;
import com.caac.core.util.Page;
import com.caac.core.web.action.BasePageViewAction;
import com.caac.core.web.action.PageViewForward;
import com.caac.core.web.form.BaseForm;
import com.ac.app.dm.PickKeyword;
import com.ac.app.web.form.PkKeywordSearchForm;
import com.ac.app.web.view.PkKeywordView;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2008</p>
 * <p>Company: AgileCentury </p>
 * @author <a href="mailto:ac@agilecentury.com">Agile</a>
 * @version 1.0
 */

public class SearchPkKeywordAction extends BasePageViewAction {

	private static final String	QUERY_NAME	= "pkKeywordQuery";
	private static final String	ORDER_NAME	= "pkKeywordOrder";
	private static final String	VIEW_NAME	= "pkKeywordView";
	protected PageViewForward doPageViewExecute(ActionMapping mapping,
			BaseForm form, HttpServletRequest request,
			HttpServletResponse response, int pageNo, int pageSize)
			throws Exception {
		PkKeywordSearchForm myForm = (PkKeywordSearchForm) form;
		QueryClass qc = getQuery(QUERY_NAME);

        Page page = new Page(getBaseManager().getCount(PickKeyword.class, qc, myForm,
				myForm.isAnd()), pageNo, pageSize);
		List dmList = getBaseManager().getObjects(PickKeyword.class, qc, myForm,
				myForm.isAnd(), getOrder(ORDER_NAME), page);
        
		List<PkKeywordView> vList = new ArrayList<PkKeywordView>();
		for (int i = 0; i < dmList.size(); i++) {
			PickKeyword dm = (PickKeyword) dmList.get(i);
			PkKeywordView dmView = new PkKeywordView();
			dmView.setPickKeyword(dm);
			vList.add(dmView);
		}
		return new PageViewForward(forward(mapping), vList, page,
				getSelViewProps(VIEW_NAME), null, null);
	}
}

